<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="content">
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form id="userView">



                <p:panel header="List of finished order ,pending to be reviewed" style="text-align: center">
                    <p:dataTable  value="#{rawMaterialPurchaseOrderEntityController.fulfilledRposs}" var="rmq" widgetVar="userTable"
                                  paginator="true" rows="10"  
                                  paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                                  selection="#{rawMaterialPurchaseOrderEntityController.selectedRpo}" selectionMode="single"
                                  rowSelectListener="#{rawMaterialPurchaseOrderEntityController.RPOSelect}">     


                        <p:column sortBy="#{rmq.rmq.vendor.companyName}" filterBy="#{rmq.rmq.vendor.companyName}">    <f:facet name="header">  
                                <h:outputText value="Vendor Name" /> </f:facet>
                            <h:outputText value="#{rmq.rmq.vendor.companyName}" /> </p:column>

                        <p:column sortBy="#{rmq.rmq.rawMaterial.productName}" filterBy="#{rmq.rmq.rawMaterial.productName}">    <f:facet name="header">  
                                <h:outputText value="Raw Material:" /> </f:facet>
                            <h:outputText value="#{rmq.rmq.rawMaterial.productName}" /> </p:column>


                        <p:column>    <f:facet name="header">  
                                <h:outputText value="Date Purchased:" /> </f:facet>
                            <h:outputText value="#{rmq.createdAt}" > 
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                        </p:column>

                    </p:dataTable> 
                </p:panel>


                <p:separator style="width:300px;height:10px" /> 
                <p:panel header="List Of Complete Purchase Order" style="text-align: center">
                    <p:dataTable  id="tbl" value="#{rawMaterialPurchaseOrderEntityController.finishedRpos}" var="rmq" widgetVar="userTable"
                                  paginator="true" rows="10"  
                                  paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">



                        <p:column sortBy="#{rmq.rmq.vendor.companyName}" filterBy="#{rmq.rmq.vendor.companyName}">    <f:facet name="header">  
                                <h:outputText value="Vendor Name" /> </f:facet>
                            <h:outputText value="#{rmq.rmq.vendor.companyName}" /> </p:column>

                        <p:column sortBy="#{rmq.rmq.rawMaterial.productName}" filterBy="#{rmq.rmq.rawMaterial.productName}">    <f:facet name="header">  
                                <h:outputText value="Raw Material:" /> </f:facet>
                            <h:outputText value="#{rmq.rmq.rawMaterial.productName}" /> </p:column>


                        <p:column sortBy="#{rmq.quantity}" filterBy="#{rmq.quantity}">    <f:facet name="header">  
                                <h:outputText value="Amount:" /> </f:facet>
                            <h:outputText value="#{rmq.quantity}" /> </p:column> 
                        <p:column sortBy="#{rmq.cost}" filterBy="#{rmq.cost}">    <f:facet name="header">  
                                <h:outputText value="Cost:" /> </f:facet>
                            <h:outputText value="#{rmq.cost}" /> </p:column> 
                        <p:column>    <f:facet name="header">  
                                <h:outputText value="Date Purchased:" /> </f:facet>
                            <h:outputText value="#{rmq.dateConfirmed}" > 
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                        </p:column>
                        <p:column sortBy="#{rmq.star}" filterBy="#{rmq.star}">    <f:facet name="header">  
                                <h:outputText value="Rating:" />

                            </f:facet>
                            <h:outputText value="#{rmq.star}" />
                            <h:outputText value="/5.0" />
                        </p:column> 

                        <p:column sortBy="#{rmq.note}" filterBy="#{rmq.note}">    <f:facet name="header">  
                                <h:outputText value="Note:" /> </f:facet>
                            <h:outputText value="#{rmq.note}" /> </p:column>
                        <p:column>
                            <p:menuButton value="Options">  
                                <p:menuitem value="More Info" ajax="false" icon="ui-icon ui-icon-disk" action ="ViewPastOrder" >
                                    <f:setPropertyActionListener value="#{rmq}"  
                                                                 target="#{rawMaterialPurchaseOrderEntityController.currRpo}" />
                                </p:menuitem>
                                <p:menuitem value=" Remove" ajax="false" icon="ui-icon ui-icon-disk" 
                                            action ="#{rawMaterialPurchaseOrderEntityController.delete1}">
                                    <f:setPropertyActionListener value="#{rmq}"  
                                                                 target="#{rawMaterialPurchaseOrderEntityController.selectedPo}" />

                                </p:menuitem> 

                            </p:menuButton>
                        </p:column>
                    </p:dataTable> 
                </p:panel>


                <h:commandLink>  
                    <p:graphicImage value="/images/pdf.png" />  
                    <p:dataExporter type="pdf" target="tbl" fileName="CompletedOrder" excludeColumns="7" preProcessor="#{export.preProcessPDF}"/>  
                </h:commandLink>  

                <h:commandLink>  
                    <p:graphicImage value="/images/csv.png" />  
                    <p:dataExporter type="csv" target="tbl" fileName="CompletedOrder" excludeColumns="7" />  
                </h:commandLink>  

                <h:commandLink>  
                    <p:graphicImage value="/images/xml.png" />  
                    <p:dataExporter type="xml" target="tbl" fileName="CompletedOrder" excludeColumns="7" />  
                </h:commandLink>  
                <br/>
                <br/>
                <p:commandButton image="ui-icon ui-icon-search" value="Generate Order Report(Refresh the page after to download the most up to date report)"  oncomplete="carDialog.show()"/>

                <br/>
                <br/>
                <h:commandLink  title="Download" rendered ="#{jasper.exist1}">  
                    <p:graphicImage value="/images/download.gif" />  
                    <p:fileDownload value="#{download.file}"/>  
                </h:commandLink>  
                <p:dialog header="Generate Order Report for the following period:" widgetVar="carDialog" resizable="false"  
                          width="900" height="400" modal="true" showEffect="explode" hideEffect="explode">  
                    <h:panelGrid columns="2" style="width: 100%;"> 
                        <p:panel header="From:"  style="width:100">


                            <p:calendar value="#{jasper.startDate}"  mode ="inline"/>               
                        </p:panel>
                        <p:panel header="To:"  style="width:100">

                            <p:calendar value="#{jasper.endDate}"  mode ="inline"/>  
                        </p:panel>
                    </h:panelGrid>
                    <h:commandLink value="Generate Report" action="#{jasper.generateRawPurchasingReport}" target="_blank"/>

                    <br/>


                </p:dialog>  
            </h:form>
        </ui:define>
    </ui:composition>

</html>